function t(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

var e = Object.assign || function(t) {
    for (var e = 1; e < arguments.length; e++) {
        var a = arguments[e];
        for (var i in a) Object.prototype.hasOwnProperty.call(a, i) && (t[i] = a[i]);
    }
    return t;
}, a = (t(require("../../../utils/filter.js")), t(require("../../../utils/util.js"))), i = t(require("../../../api/api.js"));

Component({
    options: {
        multipleSlots: !0
    },
    properties: {
        availableTimeDatum: {
            type: Array,
            value: "default value"
        },
        activeDayAvailableTime: {
            type: Object,
            value: "default value"
        },
        activeDayIndex: {
            type: Number,
            value: ""
        },
        activeHourIndex: {
            type: Number,
            value: ""
        },
        currentTeacherId: {
            type: Number,
            value: ""
        },
        cancelText: {
            type: String,
            value: "取消"
        },
        confirmText: {
            type: String,
            value: "确定"
        }
    },
    data: {
        currentTeacherId: "",
        canlMove: ""
    },
    ready: function(t) {
        if (!this.selectComponent) throw new Error("小程序sdk暂不支持节点操作selectComponent");
        this.baseModal = this.selectComponent("#baseModal");
        var e = a.default.getDateStr(1) + " 00:00", i = a.default.getDateStr(4) + " 23:59";
        this.page = 1, this.currentDate = {
            start_time: e,
            end_time: i
        };
    },
    methods: {
        _toggleSessionDay: function(t) {
            this.triggerEvent("changeSessionDay", {
                activeDayAvailableTime: t.currentTarget.dataset.activeDayAvailableTime,
                activeDayIndex: Number(t.currentTarget.id),
                activeHourIndex: ""
            });
        },
        _touchStart: function(t) {
            this.touchDot = t.touches[0].pageX, this.setData({
                canlMove: ""
            });
        },
        _touchMove: function(t) {
            this.touchMoveX = t.touches[0].pageX;
        },
        _touchEnd: function(t, r) {
            var n = this;
            if (this.touchMoveX && this.touchMoveX - this.touchDot < -75) {
                this.page = this.page + 1;
                var c = a.default.getDateStr(4 * (this.page - 1)) + " 00:00", s = a.default.getDateStr(4 * this.page) + " 23:59";
                this.currentDate = {
                    start_time: c,
                    end_time: s
                };
                var u = this.currentDate;
                this.setData(e({}, this.data, {
                    activeDayAvailableTime: [],
                    canlMove: "canlMoveLeft"
                })), i.default.getTeacherAvailableTime({
                    query: {
                        id: this.data.currentTeacherId
                    },
                    data: u,
                    success: function(t) {
                        if (t && t.data.data) {
                            var i = t.data.data.slice(0, 4);
                            i.map(function(t) {
                                t.calendar_day = a.default.formatCurrentDate(t.day).substring(5), t.week_day = a.default.getWeekByDate(t.day);
                            }), n.setData(e({}, n.data, {
                                availableTimeDatum: i,
                                activeHourIndex: "",
                                activeDayIndex: 0,
                                activeDayAvailableTime: i[0]
                            }));
                        }
                    }
                });
            }
            if (this.page > 1 && this.touchMoveX - this.touchDot > 75) {
                this.page = this.page - 1;
                var l = a.default.getDateStr(4 * (this.page - 1) || 1) + " 00:00", d = a.default.getDateStr(4 * this.page) + " 23:59";
                this.currentDate = {
                    start_time: l,
                    end_time: d
                };
                var o = this.currentDate;
                this.setData(e({}, this.data, {
                    activeDayAvailableTime: [],
                    canlMove: "canlMoveRight"
                })), i.default.getTeacherAvailableTime({
                    query: {
                        id: this.data.currentTeacherId
                    },
                    data: o,
                    success: function(t) {
                        if (t && t.data.data) {
                            var i = t.data.data.slice(0, 4);
                            i.map(function(t) {
                                t.calendar_day = a.default.formatCurrentDate(t.day).substring(5), t.week_day = a.default.getWeekByDate(t.day);
                            }), n.setData(e({}, n.data, {
                                availableTimeDatum: i,
                                activeHourIndex: "",
                                activeDayIndex: 0,
                                activeDayAvailableTime: i[0]
                            }));
                        }
                    }
                });
            }
            this.touchDot = 0, this.touchMoveX = 0;
        },
        _selectSectionTime: function(t) {
            var e = t.currentTarget.dataset.currentDay;
            this.triggerEvent("changeSessionTime", {
                activeHourIndex: Number(t.currentTarget.id),
                activeDayAvailableTime: t.currentTarget.dataset.activeDay,
                bookSectionTime: e + " " + t.currentTarget.dataset.currentHour
            });
        },
        show: function() {
            this.triggerEvent("scrollEvent", {
                noScroll: !0
            }), this.baseModal.showModal();
        },
        hide: function() {
            this.triggerEvent("scrollEvent", {
                noScroll: !1
            }), this.baseModal.hideModal();
        },
        _cancelModal: function() {
            this.hide(), this.triggerEvent("cancelEvent");
        },
        _confirmModal: function() {
            this.triggerEvent("confirmEvent"), this.hide(), this.setData({
                activeDayIndex: 0
            });
        },
        _leftArrow: function() {
            var t = this;
            this.setData({
                canlMove: "canlMoveLeft"
            }), this.page = this.page + 1;
            var r = a.default.getDateStr(4 * (this.page - 1)) + " 00:00", n = a.default.getDateStr(4 * this.page) + " 23:59";
            this.currentDate = {
                start_time: r,
                end_time: n
            };
            var c = this.currentDate;
            this.setData(e({}, this.data, {
                activeDayAvailableTime: [],
                canlMove: "canlMoveLeft"
            })), i.default.getTeacherAvailableTime({
                query: {
                    id: this.data.currentTeacherId
                },
                data: c,
                success: function(i) {
                    if (i && i.data.data) {
                        var r = i.data.data.slice(0, 4);
                        r.map(function(t) {
                            t.calendar_day = a.default.formatCurrentDate(t.day).substring(5), t.week_day = a.default.getWeekByDate(t.day);
                        }), t.setData(e({}, t.data, {
                            availableTimeDatum: r,
                            activeHourIndex: "",
                            activeDayIndex: 0,
                            activeDayAvailableTime: r[0]
                        }));
                    }
                }
            });
        },
        _rightArrow: function() {
            var t = this;
            this.setData({
                canlMove: "canlMoveRight"
            }), this.page = this.page - 1;
            var r = a.default.getDateStr(4 * (this.page - 1) || 1) + " 00:00", n = a.default.getDateStr(4 * this.page) + " 23:59";
            this.currentDate = {
                start_time: r,
                end_time: n
            };
            var c = this.currentDate;
            this.setData(e({}, this.data, {
                activeDayAvailableTime: [],
                canlMove: "canlMoveRight"
            })), i.default.getTeacherAvailableTime({
                query: {
                    id: this.data.currentTeacherId
                },
                data: c,
                success: function(i) {
                    if (i && i.data.data) {
                        var r = i.data.data.slice(0, 4);
                        r.map(function(t) {
                            t.calendar_day = a.default.formatCurrentDate(t.day).substring(5), t.week_day = a.default.getWeekByDate(t.day);
                        }), t.setData(e({}, t.data, {
                            availableTimeDatum: r,
                            activeHourIndex: "",
                            activeDayIndex: 0,
                            activeDayAvailableTime: r[0]
                        }));
                    }
                }
            });
        },
        _arrowTouchStart: function() {
            this.setData({
                canlMove: ""
            });
        }
    }
});